
package controllers.classes;

import classes.Breadcrumbs;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import models.Category;
import dao.CategoryDao;
import classes.HibernateUtil;
import classes.Url;
import dao.CourseDao;
import models.Course;

/**
 * This servlet handles the courses for the myCourse page.
 * 
 * @author Vuong Pham<Vuong.Pham@hva.nl>
 */
public class MyCourses extends HttpServlet {

    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {      
        Url.setHistory(request);
            //connection with database using Dao
            HibernateUtil hu = new HibernateUtil();
            CategoryDao ed = new CategoryDao(hu.openSession());
            CourseDao cd = new CourseDao(hu.openSession());
            List<Category> categoryList = ed.findAll();
            List<Course> courseList = cd.findAll();
                       

            RequestDispatcher dispatcher = request.getRequestDispatcher("");           
                // Breadcrumbs
                Breadcrumbs[] breadcrumbs = {
                    new Breadcrumbs("Index", "Home"),
                    new Breadcrumbs("MyCourses", "My courses")
                };
                request.setAttribute("breadcrumbs", breadcrumbs);
                
                request.setAttribute("categories", categoryList);
                dispatcher = request.getRequestDispatcher("jsp/bought_courses_view.jsp");
                dispatcher.forward(request, response);
    }
}
